package ua.kpi.javatraining.university;

/**
 * Class describing University structure. Contains parts such as groups, staff and teachers.
 * Has methods to add, get, remove certain elements and to clear all.
 *
 * @author Vasily Yatsenko
 * @version 1.1
 */
public class University extends Department implements LimitedUniversity {
    private Curriculum curriculum;
    private MiniCollection<AcademicGroup> groups;
    private MiniCollection<Professor> teachers;
    private MiniCollection<Staff> staff;

    public University(String name, String headmaster) {
        super(name, headmaster);
        groups = new MiniArrayList<AcademicGroup>();
        teachers = new MiniArrayList<Professor>();
        staff = new MiniArrayList<Staff>();
        curriculum = new Curriculum();
    }

    public void addToCurriculum(Lesson lesson) {
        curriculum.addLesson(lesson);
    }

    public String getCurriculum() {
        return curriculum.getCurriculum();
    }

    public String getCurriculum(AcademicGroup academicGroup) {
        return curriculum.getCurriculum(academicGroup);
    }

    public String getCurriculum(Student student) {
        return curriculum.getCurriculum(student);
    }

    public void addGroup(AcademicGroup group) {
        groups.add(group);
    }

    public AcademicGroup getGroup(int index) {
        return groups.get(index);
    }

    public void removeAllGroups() {
        groups.clear();
    }

    public boolean hasGroups() {
        return !groups.isEmpty();
    }

    public void addTeacher(Professor professor) {
        teachers.add(professor);
    }

    public Professor getTeacher(int index) {
        return teachers.get(index);
    }

    public void removeAllTeachers() {
        teachers.clear();
    }

    public boolean hasTeachers() {
        return !teachers.isEmpty();
    }

    public void addStaff(Staff employee) {
        staff.add(employee);
    }

    public Staff getStaff(int index) {
        return staff.get(index);
    }

    public void removeAllStaff() {
        staff.clear();
    }

    public boolean hasStaff() {
        return !staff.isEmpty();
    }

    public String getGroupsList() {
        StringBuilder sb = new StringBuilder("Groups of ");

        sb.append(this.getName());
        sb.append("\n");
        for (Object group : groups.toArray()) {
            sb.append(group);
            sb.append("\n");
        }
        return sb.toString();
    }

    public String getStaffList() {
        StringBuilder sb = new StringBuilder("Staff of ");

        sb.append(this.getName());
        sb.append("\n");
        for (Object employee : staff.toArray()) {
            sb.append(employee);
            sb.append("\n");
        }
        return sb.toString();
    }

    public String getProfessorsList() {
        StringBuilder sb = new StringBuilder("Teachers of ");

        sb.append(this.getName());
        sb.append("\n");
        for (Object professor : teachers.toArray()) {
            sb.append(professor);
            sb.append("\n");
        }
        return sb.toString();
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder("University name: ");

        builder.append(super.toString());
        return builder.toString();
    }
}
